import React, { Component } from 'react';
import PubSub from "pubsub-js"
class dwgzj extends Component {
  constructor(props) {
    super(props);
    this.state = { 
      content:''
    }
  }
  //组件渲染后调用
  componentDidMount(){
    // mag -- 消息名（saveInput）    data -- 数据
    this.pubsub_token = PubSub.subscribe("saveInput",(mag,data)=>{
      console.log(mag,data)
      this.setState({
        content:data
      })
    })
  }

  //组件销毁
  componentWillUnmount(){
    //销毁通信
    PubSub.unsubscribe(this.pubsub_token);
  }


  render() { 
    return ( 
      <div>
        <div>第五个组件content:{this.state.content}</div>
      </div>
    );
  }
  
}
 
export default dwgzj;